<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="configId" stripe>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="机构码" prop="orgId" width="300"></el-table-column>
				<el-table-column label="机构名称" prop="orgName" width="200"></el-table-column>
				<el-table-column label="管理员账号" prop="orgAdmin" width="150"></el-table-column>
				<el-table-column label="机构管理员" prop="orgAdminName" width="150"></el-table-column>
				<el-table-column label="创建时间" prop="createTime" width="180"></el-table-column>
				<el-table-column label="备注说明" prop="remark" min-width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="删除机构须慎重,确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>

			</scTable>
		</el-main>
	</el-container>

	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
import saveDialog from './save'
export default {
	name: 'setting org',
	components: {
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false
			},
			apiObj: this.$API.system.sysOrgConfig.getSysOrgConfigList,
			selection: [],
			search: {
				keyword: null
			}
		}
	},
	mounted() {
	},
	methods: {
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		table_del(row) {
			this.$prompt('请输入系统安全码', '安全确认对话框', {confirmButtonText: '确定',cancelButtonText: '取消'}).then(async({ value }) => {
				if (!value ) {
					this.$alert("系统安全码不能为空", "提示", {type: 'error'})
				}else{
					var res = await this.$API.system.sysOrgConfig.clearSysOrg.post({configId: row.configId,userSignCode:value});
					if (res.code == 200) {
						this.$refs.table.refresh()
						this.$message.success("删除成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			}).catch(() => {
				this.$message({type: 'info', message: '取消操作'});
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row)
			})
		},
		//本地更新数据
		handleSaveSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		}
	}
}
</script>

<style>
</style>
